<template>
  <div>
    <div class="bg"></div>
    <van-cell-group>
      <van-field
        label="用户名"
        placeholder="请输入用户名"
        :value="username"
        @change = "changeUsername"
      />

      <van-field
        placeholder="请输入密码"
        label="密码"
        @change = "changepassword"
        v-model="password"
        type="password"
      />
    </van-cell-group>
    <div class="btnm">
      <van-button type="info" icon="user-circle-o" @click="loginGo" block>登 录</van-button>
    </div>
    <van-toast id="van-toast" />
  </div>
</template>

<script>
  import Toast from  '../../../static/vant/toast/toast';

  import {userLogin} from '../../api/basisMG'

  export default {
    data () {
      return {
        username:"",
        password:""
      }
    },
    methods: {
      changeUsername(data){
        this.username = data.mp.detail
      },
      changepassword(data){
        this.password = data.mp.detail
      },
      loginGo(){
        let userflag =false
        if(this.username==""||this.password==""){
          Toast.fail({
            message: "请填写用户名密码"
          });
          return false
        }
        userLogin({
          username:this.username,
          password:this.password
        }).then((data)=>{
          if(data.success){
            userflag =true
            wx.setStorageSync('loginInfo', {
              "username":this.username,
              "password":this.password
            })
            wx.navigateTo({
              url: "/pages/index/main"
            })
          }else{
            Toast.fail({
              message: data.msg
            });
          }
        })



      }
    }
  }
</script>

<style>

  .bg{
    background-image: url("http://39.101.138.78:25811/img/indexbg.jpg");
    background-size: 100%;
    background-repeat: no-repeat;
    background-position: top;
    padding-top: 600rpx;
  }


  .btnm{padding: 32rpx}


</style>




